import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

const routes = [
  {
    path: '/',
    name: 'Login',
    component: () => import('../views/Login.vue')
  },
  {
    path: "/",
    name: 'Index',
    component: () => import('../views/Index.vue'),
    children: [
      {
        path : "dashboard",
        name : "Dashboard",
        component: () => import('../views/Dashboard.vue'),
        meta: {requireAuth: true, keepAlive: true}
      },
      {
        path: "/pwdsetting",
        name: "PwdSetting",
        component: () => import('../views/PwdSetting.vue'),
        meta: {requireAuth: true, keepAlive: true}
      },
      {
        path: "/transfer",
        name: "Transfer",
        component: () => import('../views/Transfer.vue'),
        meta: {requireAuth: true, keepAlive: true}
      },
      {
        //银证转账查询
        path: '/transferquery',
        name: 'TransferQuery',
        component: () => import( '../views/TransferQuery.vue'),
        meta: {requireAuth: true, keepAlive: true}
      },
      {
        path: "/orderquery",
        name: "OrderQuery",
        component: () => import('../views/OrderQuery.vue'),
        meta: {requireAuth: true, keepAlive: true}
      },
      {
        //当日成交
        path: '/tradequery',
        name: 'TradeQuery',
        component: () => import( '../views/TradeQuery.vue'),
        meta: {requireAuth: true, keepAlive: true}
      },
      {
        //历史委托
        path: '/hisorderquery',
        name: 'HisOrderQuery',
        component: () => import( '../views/HisOrderQuery.vue'),
        meta: {requireAuth: true, keepAlive: true}
      },
      {
        //历史成交
        path: '/histradequery',
        name: 'HisTradeQuery',
        component: () => import( '../views/HisTradeQuery.vue'),
        meta: {requireAuth: true, keepAlive: true}
      },
      {
        //委托买入
        path: '/buy',
        name: 'Buy',
        component: () => import( '../views/Buy.vue'),
        meta: {requireAuth: true, keepAlive: true}
      },
      {
        //委卖
        path: '/sale',
        name: 'Sale',
        component: () => import('../views/Sale.vue'),
        meta: {requireAuth: true, keepAlive: true}
      },
      {
        path: '/404',
        name: '404',
        component: () => import("../views/404.vue"),
        meta: {requireAuth: false, keepAlive: true}
      },
      {
        path: '*',
        redirect: '/404',
        meta: {requireAuth: false, keepAlive: true}
      },
    ]
  }
]

const router = new Router({
  mode: 'history',
  routes
})

router.beforeEach((to, fromm, next) => {
  console.log(to.path)
  if (to.meta.requireAuth) {
    if (Boolean(sessionStorage.getItem("uid"))) {
      console.log(11)
      next();
    }else {
      next({
        path: "/" // 需要验证，去到登录页面
      })
    }
  }else {
    next()
  }
})

export default router
